package com.example.demo.controller;

import com.example.demo.pojo.Person;
import com.example.demo.service.HelloService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class HelloController {

    @Resource
    private HelloService helloService;

    @RequestMapping("/get")
    public Person get(){
        return helloService.getById(1);
    }

    @RequestMapping("/get2")
    public Person getBYPerson(){
        Person person=new Person();
        person.setId(2);
        person.setName("瓜田李下 2");
        person.setAge(21);

        return helloService.getByPerson(person);
    }

    @RequestMapping("/put")
    public Person put(){
        return helloService.put(1,"瓜田李下",20);
    }

    @RequestMapping("/put2")
    public Person put2(){
        Person person=new Person();
        person.setId(2);
        person.setName("瓜田李下 2");
        person.setAge(21);

        return helloService.put2(person);
    }

    @RequestMapping("/delete")
    public Person delete(){
        return helloService.deleteById(1);
    }

    @RequestMapping("/delete2")
    public Person delete2(){
        Person person=new Person();
        person.setId(2);
        person.setName("瓜田李下 2");
        person.setAge(21);

        return helloService.delete2(person);
    }
}
